//
//  TLS_FirstPageVC.m
//  Travel_World
//
//  Created by lanou on 15/10/12.
//  Copyright © 2015年 TLS. All rights reserved.
//

#import "TLS_FirstPageVC.h"
#import "SSCarouselFigure.h"
#import "SSFirstPageBoutiqueModel.h"
#import "QTAFNnetWorkTool.h"
#import "UIImageView+WebCache.h"
#import "UIButton+WebCache.h"
#import "SSFirstPageTravelModel.h"
#import "SSFirstPageTravelCell.h"
#import "SSFirstPageDiscountCell.h"
#import "SSFirstPageWebView.h"
#import "SSFirstPageDiscountView.h"
#import "SSFirstPageTravelView.h"
#import "SSFirstPageBookingHotelView.h"
#import "SSCollectionModel.h"
#import "SSFirstPageButtonCell.h"

@interface TLS_FirstPageVC ()<UIScrollViewDelegate, SSCarouselFigureDelegate, UITableViewDataSource, UITableViewDelegate, UICollectionViewDataSource, UICollectionViewDelegate>

@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIBarButtonItem *leftBarButtonItem;
@property (nonatomic, strong) UIBarButtonItem *rightBarButtonItem;
@property (nonatomic, strong) UIScrollView *mainScrollView;
@property (nonatomic, strong) UIScrollView *boutiqueScrollView;
@property (nonatomic, strong) UITableView *travelTableView;
@property (nonatomic, strong) SSCarouselFigure *carouselFigureView;
@property (nonatomic, strong) NSMutableArray *carouselFigureArr;
@property (nonatomic, strong) NSMutableArray *travelDataArr;
@property (nonatomic, strong) NSMutableArray *subjectArr;
@property (nonatomic, strong) SSFirstPageBoutiqueModel *discountSubject;
@property (nonatomic, strong) NSMutableArray *discountArr;
@property (nonatomic, strong) UICollectionView *discountCollectionView;
@property (nonatomic, strong) UICollectionView *buttonCollectionView;

@end

@implementation TLS_FirstPageVC

- (void)viewDidAppear:(BOOL)animated{
    
    [super viewDidAppear:animated];
    self.hidesBottomBarWhenPushed = YES;
    
    NSDictionary *dic = @{@"1" : @"1"};
    [[NSNotificationCenter defaultCenter] postNotificationName:@"timer" object:nil userInfo:dic];
    
}


- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.translucent = NO;
    self.tabBarController.tabBar.hidden = NO;
}

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    self.hidesBottomBarWhenPushed = NO;
    
    NSDictionary *dic = @{@"1" : @"2"};
    [[NSNotificationCenter defaultCenter] postNotificationName:@"timer" object:nil userInfo:dic];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor cyanColor];
    self.navigationController.navigationBar.translucent = NO;
   // self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0.949 green:0.179 blue:1.000 alpha:1.000];
    
    [self createTitle];
    [self createBarButton];
    [self createMainScrollView];
    [self createBoutiqueScrollView];                    
    [self createTravelTableView];
    [self createCarouselFigureView];
    [self createCarouselFigureAfterView];
    [self createData];

}

- (void)createTitle
{
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, WIDTH / 4, 30)];
    self.titleLabel.text = @"精品推荐";
    self.titleLabel.font = [UIFont systemFontOfSize:20];
    //self.titleLabel.textColor = [UIColor whiteColor];
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    self.navigationItem.titleView = self.titleLabel;
}

- (void)createBarButton
{
    self.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"<< 精品" style:UIBarButtonItemStyleDone target:self action:@selector(leftBarButtonItemClick)];
    self.leftBarButtonItem.tintColor = [UIColor clearColor];
    self.leftBarButtonItem.enabled = NO;
    self.navigationItem.leftBarButtonItem = self.leftBarButtonItem;
    
    self.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"游记 >>" style:UIBarButtonItemStyleDone target:self action:@selector(rightBarButtonItemClick)];
    self.rightBarButtonItem.tintColor = GBCOLOR;
    self.navigationItem.rightBarButtonItem = self.rightBarButtonItem;
}

- (void)createMainScrollView
{
    self.mainScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT - 49)];
    self.mainScrollView.contentSize = CGSizeMake(2 * WIDTH, HEIGHT - 49);
    self.mainScrollView.backgroundColor = [UIColor grayColor];
    self.mainScrollView.showsHorizontalScrollIndicator = NO;
    self.mainScrollView.pagingEnabled = YES;
    self.mainScrollView.bounces = NO;
    self.mainScrollView.delegate = self;
    [self.view addSubview:self.mainScrollView];
}

- (void)createBoutiqueScrollView
{
    self.boutiqueScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT - 49)];
    self.boutiqueScrollView.contentSize = CGSizeMake(WIDTH, 1180 * HEI);
    self.boutiqueScrollView.backgroundColor = [UIColor whiteColor];
    self.boutiqueScrollView.showsVerticalScrollIndicator = NO;
    [self.mainScrollView addSubview:self.boutiqueScrollView];
}

- (void)createTravelTableView
{
    self.travelTableView = [[UITableView alloc] initWithFrame:CGRectMake(WIDTH, 0, WIDTH, HEIGHT - 49) style:UITableViewStylePlain];
    self.travelTableView.backgroundColor = [UIColor whiteColor];
    self.travelTableView.showsVerticalScrollIndicator = NO;
    self.travelTableView.rowHeight = 115;
    [self.mainScrollView addSubview:self.travelTableView];
    self.travelTableView.delegate = self;
    self.travelTableView.dataSource = self;
    [self.travelTableView registerClass:[SSFirstPageTravelCell class] forCellReuseIdentifier:@"travel"];
}

- (void)createCarouselFigureView
{
    self.carouselFigureView = [[SSCarouselFigure alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 200 * HEI)];
    self.carouselFigureView.delegate = self;
    [self.boutiqueScrollView addSubview:self.carouselFigureView];
}

- (void)createCarouselFigureAfterView
{
    UIImageView *backgroundView = [[UIImageView alloc] initWithFrame:CGRectMake(10 * WID, 205 * HEI, WIDTH - 20 * WID, 90 * HEI)];
    backgroundView.image = [UIImage imageNamed:@"A516Y1D5[G28ZD5PLON[7I1.jpg"];
    [self.boutiqueScrollView addSubview:backgroundView];
    
    
    UICollectionViewFlowLayout *buttonLayout = [[UICollectionViewFlowLayout alloc] init];
    buttonLayout.itemSize = CGSizeMake(WIDTH * 0.2, 80 * HEI);
    buttonLayout.minimumLineSpacing = WIDTH * 0.1;
    buttonLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    buttonLayout.sectionInset = UIEdgeInsetsMake(0, 0.1 * WIDTH, 0, WIDTH * 0.1);
    
    self.buttonCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 210 * HEI, WIDTH, 80 * HEI) collectionViewLayout:buttonLayout];
    self.buttonCollectionView.pagingEnabled = YES;
    self.buttonCollectionView.showsHorizontalScrollIndicator = NO;
    self.buttonCollectionView.bounces = NO;
    self.buttonCollectionView.backgroundColor = [UIColor clearColor];
    [self.boutiqueScrollView addSubview:self.buttonCollectionView];
    self.buttonCollectionView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0.9375 * WIDTH);
    self.buttonCollectionView.contentOffset = CGPointMake(0.9375 * WIDTH, 0);

    self.buttonCollectionView.delegate = self;
    self.buttonCollectionView.dataSource = self;
    [self.buttonCollectionView registerClass:[SSFirstPageButtonCell class] forCellWithReuseIdentifier:@"button"];
    
    
    UILabel *findNextLabel = [[UILabel alloc] initWithFrame:CGRectMake(10 * WID, 300 * HEI, WIDTH - 20 * WID, 30 * HEI)];
    findNextLabel.text = @"发现下一站";
    [self.boutiqueScrollView addSubview:findNextLabel];
    
    UIButton *findNextBigButton = [UIButton buttonWithType:UIButtonTypeCustom];
    findNextBigButton.frame = CGRectMake(10 * W, 340 * HEI, WIDTH - 20 * W, 160 * HEI);
    findNextBigButton.tag = 1000;
    [findNextBigButton setBackgroundImage:[UIImage imageNamed:@"placeholder1"] forState:UIControlStateNormal];
    [self.boutiqueScrollView addSubview:findNextBigButton];
    [findNextBigButton addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *findNextLeftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    findNextLeftButton.frame = CGRectMake(10 * W, 510  * HEI, ( WIDTH - 30 * W ) / 2, 110 * HEI);
    findNextLeftButton.tag = 1001;
    [findNextLeftButton setBackgroundImage:[UIImage imageNamed:@"placeholder1"] forState:UIControlStateNormal];
    [self.boutiqueScrollView addSubview:findNextLeftButton];
    [findNextLeftButton addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *findNextRightButton = [UIButton buttonWithType:UIButtonTypeCustom];
    findNextRightButton.frame = CGRectMake(WIDTH / 2 + 5 * W, 510 * HEI, ( WIDTH - 30 * W ) / 2, 110  * HEI);
    findNextRightButton.tag = 1002;
    [findNextRightButton setBackgroundImage:[UIImage imageNamed:@"placeholder1"] forState:UIControlStateNormal];
    [self.boutiqueScrollView addSubview:findNextRightButton];
    [findNextRightButton addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    
    
    UILabel *discountLabel = [[UILabel alloc] initWithFrame:CGRectMake(10 * W, 640 * HEI, WIDTH - 10 * W, 30  * HEI)];
    discountLabel.text = @"特价折扣";
    [self.boutiqueScrollView addSubview:discountLabel];
    
    UIButton *moreDiscountButton = [[UIButton alloc] initWithFrame:CGRectMake(WIDTH * 0.8, 640  * HEI, WIDTH * 0.2, 30  * HEI)];
    [moreDiscountButton setTitle:@"更多" forState:UIControlStateNormal];
    [moreDiscountButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [moreDiscountButton addTarget:self action:@selector(moreDiscountButtonClick) forControlEvents:UIControlEventTouchUpInside];
    
    [self.boutiqueScrollView addSubview:moreDiscountButton];
    
    UIButton *discountBigButton = [UIButton buttonWithType:UIButtonTypeCustom];
    discountBigButton.frame = CGRectMake(10 * W, 680  * HEI, WIDTH - 20 * W, 160 * HEI);
    discountBigButton.tag = 2000;
    [discountBigButton setBackgroundImage:[UIImage imageNamed:@"placeholder1"] forState:UIControlStateNormal];
    [self.boutiqueScrollView addSubview:discountBigButton];
    [discountBigButton addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.itemSize = CGSizeMake((WIDTH - 30 * W) / 2, 150 * H);
    flowLayout.minimumInteritemSpacing = 9 * W;
    flowLayout.minimumLineSpacing = 9 * H;
    flowLayout.sectionInset = UIEdgeInsetsMake(10 * H, 10 * W, 10 * H, 10 * W);
    
    self.discountCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 840 * HEI, WIDTH, 330 * H) collectionViewLayout:flowLayout];
    self.discountCollectionView.backgroundColor = [UIColor whiteColor];
    [self.boutiqueScrollView addSubview:self.discountCollectionView];
    
    self.discountCollectionView.delegate = self;
    self.discountCollectionView.dataSource = self;
    
    [self.discountCollectionView registerClass:[SSFirstPageDiscountCell class] forCellWithReuseIdentifier:@"discount"];
}

- (void)createData
{
    [QTAFNnetWorkTool getUrl:@"http://open.qyer.com/qyer/recommands/entry?client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&page=1&track_app_channel=App%2520Store&track_app_version=6.6&track_device_info=iPad%2520Air%2520%28Wifi%29&track_deviceid=A24310D6-4784-474E-86CE-81D543A1EB8A&track_os=ios%25208.1.3&v=1" body:nil hudSuperView:self.boutiqueScrollView result:QTJSON headerFile:nil success:^(id result) {
        
        self.carouselFigureArr = [SSFirstPageBoutiqueModel baseModelByArr:result[@"data"][@"slide"]];
        
        NSMutableArray *arr = @[].mutableCopy;
        for (SSFirstPageBoutiqueModel *carouselFigureModel in self.carouselFigureArr) {
            [arr addObject:carouselFigureModel.photo];
        }
        
        [self.carouselFigureView createColletionViewByArr:arr];
        
        self.subjectArr =[SSFirstPageBoutiqueModel baseModelByArr:result[@"data"][@"subject"]];
        
        if (!self.discountSubject) {
            self.discountSubject = [[SSFirstPageBoutiqueModel alloc] init];
        }
        
        [self.discountSubject setValuesForKeysWithDictionary:result[@"data"][@"discount_subject"][0]];
        [self setButtonImage];
        
        self.discountArr=[SSFirstPageBoutiqueModel baseModelByArr:result[@"data"][@"discount"]];
        
        [self.discountCollectionView reloadData];
        
    }];
    
    
    [QTAFNnetWorkTool getUrl:@"http://open.qyer.com/qyer/recommands/trip?client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=10&lat=38.88260634985181&lon=121.5398368146665&page=1&track_app_channel=App%2520Store&track_app_version=6.5.5&track_device_info=iPhone7%2C2&track_deviceid=5B302CA5-E537-4B10-955D-520F4C91BAFE&track_os=ios%25208.1.2&type=index&v=1%20HTTP/1.1Host:%20open.qyer.com" body:nil hudSuperView:self.travelTableView result:QTJSON headerFile:nil success:^(id result) {
        
        self.travelDataArr = [SSFirstPageTravelModel baseModelByArr:result[@"data"]];
        
        NSLog(@"%ld", self.travelDataArr.count);
        
        [self.travelTableView reloadData];
        
    }];
    
}


- (void)leftBarButtonItemClick
{
    [UIScrollView animateWithDuration:0.5 animations:^{
        
        self.mainScrollView.contentOffset = CGPointMake(0, 0);
        self.titleLabel.alpha = 0;
        
    } completion:^(BOOL finished) {
        
        self.titleLabel.text = @"精品推荐";
        self.titleLabel.alpha = 1;
    }];
    
    
    self.rightBarButtonItem.enabled = YES;
    self.rightBarButtonItem.tintColor = GBCOLOR;
    self.leftBarButtonItem.enabled = NO;
    self.leftBarButtonItem.tintColor = [UIColor clearColor];
    
    [self.travelTableView setContentOffset:self.travelTableView.contentOffset animated:NO];
}


- (void)rightBarButtonItemClick
{
    [UIScrollView animateWithDuration:0.5 animations:^{
        
        self.mainScrollView.contentOffset = CGPointMake(WIDTH, 0);
        self.titleLabel.alpha = 0;
        
    } completion:^(BOOL finished) {
        
        self.titleLabel.text = @"热门游记";
        self.titleLabel.alpha = 1;
    }];
    
    self.rightBarButtonItem.enabled = NO;
    self.rightBarButtonItem.tintColor = [UIColor clearColor];
    self.leftBarButtonItem.enabled = YES;
    self.leftBarButtonItem.tintColor = GBCOLOR;
    
    [self.boutiqueScrollView setContentOffset:self.boutiqueScrollView.contentOffset animated:NO];
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    if (self.discountCollectionView == collectionView) {
        
        return self.discountArr.count;
    } else {
        return 3;
    }
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.discountCollectionView == collectionView) {
        SSFirstPageDiscountCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"discount" forIndexPath:indexPath];
        
        if (self.discountArr.count > indexPath.row) {
            
            SSFirstPageBoutiqueModel *boutiqueModel = self.discountArr[indexPath.row];
            
            [cell.discountImageView sd_setImageWithURL:[NSURL URLWithString:boutiqueModel.photo] placeholderImage:[UIImage imageNamed:@"placeholder1"]];
            cell.titleLabel.text = boutiqueModel.title;
            cell.priceOffLabel.text = boutiqueModel.priceoff;
            
            NSMutableAttributedString *priceStr=[[NSMutableAttributedString alloc ]initWithData:[boutiqueModel.price dataUsingEncoding:NSUnicodeStringEncoding] options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
            
            NSRange range  = NSMakeRange(0, priceStr.length - 2);
            
            [priceStr setAttributes:@{NSForegroundColorAttributeName:[UIColor redColor], NSFontAttributeName:[UIFont systemFontOfSize:16]} range:range];
            cell.priceLabel.attributedText = priceStr;
        }
        
        return cell;
    } else {
        
        SSFirstPageButtonCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"button" forIndexPath:indexPath];
        if (indexPath.row == 0) {
            cell.myImageView.image = [UIImage imageNamed:@"a76390cd634ef4127c2ee21b3fc07100"];
        }
        if (indexPath.row == 1) {
            cell.myImageView.image = [UIImage imageNamed:@"ab32f49557bff32060f28cf43bc6bae8"];
        }
        if (indexPath.row == 2) {
            cell.myImageView.image = [UIImage imageNamed:@"2b699d8e364ceade493f21986e37d0bc"];
        }


        
        return cell;
    }
    
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.discountCollectionView == collectionView) {
        SSCollectionModel *collectionModel = [[SSCollectionModel alloc] init];
        
        SSFirstPageWebView *firstPageWebView = [[SSFirstPageWebView alloc] init];
        if (self.discountArr.count > indexPath.row) {
            
            SSFirstPageBoutiqueModel *boutiqueModel = self.discountArr[indexPath.row];
            firstPageWebView.myURL = [NSString stringWithFormat:@"http://m.qyer.com/z/deal/%@/?source=app&client_id=qyer_ios&track_app_version=6.5.5&track_deviceid=5B302CA5-E537-4B10-955D-520F4C91BAFE&track_user_id=6654242",boutiqueModel.myid];
            
            collectionModel.title = boutiqueModel.title;
            collectionModel.pic = boutiqueModel.photo;
            collectionModel.price = boutiqueModel.price;
            collectionModel.url = firstPageWebView.myURL;
            
            firstPageWebView.collectionModel = collectionModel;
        }
        
        [self.navigationController pushViewController:firstPageWebView animated:YES];
    }
    
    if (self.buttonCollectionView == collectionView) {
        
        if (indexPath.row == 0) {
            
            SSFirstPageDiscountView *firstPageDiscountView = [[SSFirstPageDiscountView alloc] init];
            [self.navigationController pushViewController:firstPageDiscountView animated:YES];
            
        } else if(indexPath.row == 1) {
            
            SSFirstPageBookingHotelView *firstPageBookingHotelView = [[SSFirstPageBookingHotelView alloc] init];
            [self.navigationController pushViewController:firstPageBookingHotelView animated:YES];
            
        } else if(indexPath.row == 2) {
            
            SSFirstPageTravelView *firstPageTravelView = [[SSFirstPageTravelView alloc] init];
            firstPageTravelView.ifReturnLastInterface = NO;
            UINavigationController *firstPageTravelNC = [[UINavigationController alloc] initWithRootViewController:firstPageTravelView];
            [self presentViewController:firstPageTravelNC animated:YES completion:nil];
            
        }
    }    
}


- (void)moreDiscountButtonClick
{
    SSFirstPageDiscountView *firstPageDiscountView = [[SSFirstPageDiscountView alloc] init];
    [self.navigationController pushViewController:firstPageDiscountView animated:YES];
}

- (void)setButtonImage
{
    for (int i = 0; i < 3; i++) {
        UIButton *button = (UIButton *)[self.boutiqueScrollView viewWithTag:1000 + i];
        if (self.subjectArr.count > i) {
            
            [button sd_setBackgroundImageWithURL:[NSURL URLWithString:[self.subjectArr[i] photo]] forState:UIControlStateNormal];
        }
    }
    
    UIButton *button = (UIButton *)[self.boutiqueScrollView viewWithTag:2000];
    [button sd_setBackgroundImageWithURL:[NSURL URLWithString:self.discountSubject.photo] forState:UIControlStateNormal];
}


- (void)buttonClick:(UIButton *)button
{
    SSFirstPageWebView *firstPageWebView = [[SSFirstPageWebView alloc] init];
    
    switch (button.tag) {
        case 1000:
            firstPageWebView.myURL = (NSString *)[self.subjectArr[0] url];
            break;
            
        case 1001:
            firstPageWebView.myURL = (NSString *)[self.subjectArr[1] url];
            break;
            
        case 1002:
            firstPageWebView.myURL = (NSString *)[self.subjectArr[2] url];
            break;
            
        case 2000:
            firstPageWebView.myURL = self.discountSubject.url;
            break;
            
        default:
            return;
            break;
    }
    
    [self.navigationController pushViewController:firstPageWebView animated:YES];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.travelDataArr.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    SSFirstPageTravelCell *cell = [tableView dequeueReusableCellWithIdentifier:@"travel"];
    
    if (self.travelDataArr.count > indexPath.row) {
        
        SSFirstPageTravelModel *travelModel = self.travelDataArr[indexPath.row];
        cell.titleLabel.text = travelModel.title;
        cell.authorLabel.text = travelModel.username;
        [cell.LeftImageView sd_setImageWithURL:[NSURL URLWithString:travelModel.photo] placeholderImage:[UIImage imageNamed:@"placeholder1"]];
        cell.seeLabel.text = [NSString stringWithFormat:@"👀 %@", travelModel.views];
        cell.informationLabel.text = [NSString stringWithFormat:@"💬 %@", travelModel.replys];
    }
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    SSFirstPageWebView *firstPageWebView = [[SSFirstPageWebView alloc] init];
    firstPageWebView.myURL = [self.travelDataArr[indexPath.row] view_url];
    [self.navigationController pushViewController:firstPageWebView animated:YES];
}

- (void)clickCarouselFigureItem:(NSInteger)item
{
    SSFirstPageWebView *firstPageWebView = [[SSFirstPageWebView alloc] init];
    SSFirstPageBoutiqueModel *boutiqueModel = self.carouselFigureArr[item];
    
    firstPageWebView.myURL = boutiqueModel.url;
    NSLog(@"%@", boutiqueModel.url);
    [self.navigationController pushViewController:firstPageWebView animated:YES];
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    if (scrollView == self.mainScrollView) {
        
        if (scrollView.contentOffset.x == 0) {
            self.rightBarButtonItem.enabled = YES;
            self.rightBarButtonItem.tintColor = GBCOLOR;
            self.leftBarButtonItem.enabled = NO;
            self.leftBarButtonItem.tintColor = [UIColor clearColor];
            self.titleLabel.text = @"精品推荐";
            
        }
        
        if (scrollView.contentOffset.x == 375) {
            self.rightBarButtonItem.enabled = NO;
            self.rightBarButtonItem.tintColor = [UIColor clearColor];
            self.leftBarButtonItem.enabled = YES;
            self.leftBarButtonItem.tintColor = GBCOLOR;
            self.titleLabel.text = @"热门游记";
        }
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
